package com.ssl.order.controller;

import com.alipay.api.AlipayApiException;
import com.ssl.common.response.CommonResponse;
import com.ssl.order.pojo.OderPageRequest;
import com.ssl.order.pojo.OrderPageResponse;
import com.ssl.order.pojo.OrderSubmitRequest;
import com.ssl.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 创建订单页
     * @param oderPageRequests
     * @param personId
     * @return
     */
    @PostMapping("/createOrderPage")
    public OrderPageResponse createOrderPage(@RequestBody List<OderPageRequest> oderPageRequests,
                                             @RequestHeader String personId) {
        return orderService.createOrderPage(oderPageRequests, personId);
    }
    /**
     * 提交订单 submitOrder
     */
    @PostMapping("/submitOrder")
    public CommonResponse submitOrder(@RequestBody OrderSubmitRequest orderSubmitRequest) {
        return orderService.submitOrder(orderSubmitRequest);
    }
    @PostMapping("/cancelOrder")
    public CommonResponse cancelOrder(@RequestParam String orderId) {
        return orderService.cancelOrder(orderId);
    }

    @PostMapping("/payOrder")
    public CommonResponse payOrder(@RequestParam String orderId, @RequestParam Integer payType) {
        return orderService.payOrder(orderId, payType);
    }

    @RequestMapping("/alipaycallback")
    public CommonResponse alipaycallback(HttpServletRequest request) throws UnsupportedEncodingException, AlipayApiException {
        return orderService.alipaycallback(request);
    }
}
